<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="5" :sm="15">
            <a-form-item :label="i18n('form.relTypeId','关系类型ID')">
              <a-input :placeholder="i18n('form.relTypeId','关系类型ID','input')" v-model="queryParam.relTypeId"/>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="15">
            <a-form-item :label="i18n('form.relTypeKey','关系类型KEY')">
              <a-input :placeholder="i18n('form.relTypeKey','关系类型KEY','input')" v-model="queryParam.relTypeKey"/>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="15">
            <a-form-item :label="i18n('form.party1','当前方ID')">
              <a-input :placeholder="i18n('form.party1','当前方ID','input')" v-model="queryParam.party1"/>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="15">
            <a-form-item :label="i18n('form.party2','关联方ID')">
              <a-input :placeholder="i18n('form.party2','关联方ID','input')" v-model="queryParam.party2"/>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="15">
            <a-form-item :label="i18n('form.dim1','当前方维度ID')">
              <a-input :placeholder="i18n('form.dim1','当前方维度ID','input')" v-model="queryParam.dim1"/>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="15">
            <a-form-item :label="i18n('form.dim2','关联方维度ID')">
              <a-input :placeholder="i18n('form.dim2','关联方维度ID','input')" v-model="queryParam.dim2"/>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="15">
            <a-form-item label="IS_MAIN_">
              <a-input :placeholder="$ti18('rxDecorator.input','请输入')+'IS_MAIN_'" v-model="queryParam.isMain"/>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="15">
            <a-form-item :label="i18n('form.status','状态')">
              <a-input :placeholder="i18n('form.status','状态','input')" v-model="queryParam.status"/>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="15">
            <a-form-item :label="$ti18('rxForm.rxAlias','别名')">
              <a-input :placeholder="$ti18('rxForm.rxAlias','别名','','input')" v-model="queryParam.alias"/>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="15">
            <a-form-item :label="i18n('form.relType','关系类型')">
              <a-input :placeholder="i18n('form.relType','关系类型','input')" v-model="queryParam.relType"/>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="15">
            <a-form-item :label="i18n('form.createBy','创建人ID')">
              <a-input :placeholder="i18n('form.createBy','创建人ID','input')" v-model="queryParam.createBy"/>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="15">
            <a-form-item :label="i18n('form.updateBy','更新人ID')">
              <a-input :placeholder="i18n('form.updateBy','更新人ID','input')" v-model="queryParam.updateBy"/>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="15">
            <a-form-item :label="i18n('form.tenantId','租用机构ID')">
              <a-input :placeholder="i18n('form.tenantId','租用机构ID')" v-model="queryParam.tenantId"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="$refs.table.refresh(true)">{{$ti18('rxList.searchBtn','查询')}}</a-button>
              <a-button style="margin-left: 8px" @click="() => queryParam = {}">{{$ti18('rxList.resetBtn','重置')}}</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
     <div class="table-operator">
      <a-button  type="primary" icon="plus" @click="$refs.modal.add()">{{$ti18('rxList.newBtn','新建')}}</a-button>
      <a-dropdown v-if=" selectedRowKeys.length > 0">
        <a-button type="danger" icon="delete" @click="delByIds(selectedRowKeys)">{{$ti18('rxList.delBtn','删除')}}</a-button>
      </a-dropdown>
    </div>
    <s-table
      size="default"
      ref="table"
      rowKey="instId"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      :columns="columns"
      :data="loadData"
    >
      <span slot="action" slot-scope="text, record" class="actionIcons">
        <span   @click="handleEdit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
        <span   @click="delByIds([record.instId])">{{$ti18('rxList.delBtn','删除')}}</span>
      </span>
    </s-table>
    <os-rel-inst-edit ref="modal" @ok="handleOk"/>
  </a-card>
</template>

<script>
import OsRelInstApi from '@/api/user/org/osRelInst'
import OsRelInstEdit from './OsRelInstEdit.vue'

export default {
  name: 'TableList',
  components: {
    OsRelInstEdit
  },
  data () {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      form: this.$form.createForm(this),
      mdl: {},
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: this.i18n('form.relTypeId','关系类型ID'),
          dataIndex: 'relTypeId'
        },
        {
          title: this.i18n('form.relTypeKey','关系类型KEY'),
          dataIndex: 'relTypeKey'
        },
        {
          title: this.i18n('form.party1','当前方ID'),
          dataIndex: 'party1'
        },
        {
          title: this.i18n('form.party2','关联方ID'),
          dataIndex: 'party2'
        },
        {
          title: this.i18n('form.dim1','当前方维度ID'),
          dataIndex: 'dim1'
        },
        {
          title: this.i18n('form.dim2','关联方维度ID'),
          dataIndex: 'dim2'
        },
        {
          title: 'IS_MAIN_',
          dataIndex: 'isMain'
        },
        {
          title: this.i18n('form.status','状态'),
          dataIndex: 'status'
        },
        {
          title: this.$ti18('rxForm.rxAlias','别名'),
          dataIndex: 'alias'
        },
        {
          title: this.i18n('form.relType','关系类型'),
          dataIndex: 'relType'
        },
        {
          title: this.i18n('form.path','路径'),
          dataIndex: 'path'
        },
        {
          title: this.i18n('form.createBy','创建人ID'),
          dataIndex: 'createBy'
        },
        {
          title: this.$ti18('rxForm.createTime','创建时间'),
          dataIndex: 'createTime',
          sorter: true
        },
        {
          title: this.i18n('form.updateBy','更新人ID'),
          dataIndex: 'updateBy'
        },
        {
          title: this.$ti18('rxForm.updateTime','更新时间'),
          dataIndex: 'updateTime',
          sorter: true
        },
        {
          title: this.i18n('form.tenantId','租用机构ID'),
          dataIndex: 'tenantId'
        },
        {
          title: this.$ti18('rxList.action','操作'),
          width: '200px',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return OsRelInstApi.getOsRelInstList(Object.assign(parameter, this.queryParam))
      },
      selectedRowKeys: [],
      selectedRows: []
    }
  },
  filters: {
  },
  created () {
  },
  methods: {
    i18n(name,text,key){
        return this.$ti18(name,text,"OsRelInst",key);
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    handleAdd () {
      this.$refs.modal.add()
    },
    handleEdit (record) {
      this.$refs.modal.edit(record)
    },
    handleOk () {
      this.$refs.table.refresh(true)
      console.log('handleSaveOk')
    },
    delByIds (ids) {
      OsRelInstApi.delOsRelInst({ ids: ids.join(',') }).then(res => {
        if (res.code === 0) {
          this.$message.success(this.$ti18('rxMsa.deleteSuccess','删除成功'))
          this.handleOk()
        } else {
          this.$message.error(res.msg)
        }
        this.selectedRowKeys = []
      })
    }
  },
  watch: {
    /*
      'selectedRows': function (selectedRows) {
        this.needTotalList = this.needTotalList.map(item => {
          return {
            ...item,
            total: selectedRows.reduce( (sum, val) => {
              return sum + val[item.dataIndex]
            }, 0)
          }
        })
      }
      */
  }
}
</script>
